package cn.com.elite;

import javax.servlet.http.HttpServlet;
import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.ebao.gs.integration.sms.service.InternalSMSService;
import com.ebao.gs.integration.sms.sybase365.SMSSenderImpl;

public class SMSServlet extends HttpServlet{
	private static final Log log=LogFactory.getLog(SMSServlet.class);
	private SMSThread sMSThread;
	
	public void init(){
		sMSThread=new SMSThread();
		sMSThread.setTimes(this.getInitParameter("HZ"));
		sMSThread.setSql(this.getInitParameter("SQL"));
		InternalSMSService service=(InternalSMSService) WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()).getBean("com.ebao.gs.integration.sms.spi.SMSService");
		sMSThread.setService(service);
		SMSSenderImpl senderImpl=(SMSSenderImpl)WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()).getBean("com.ebao.gs.integration.sms.spi.SMSSender");
		sMSThread.setSenderImpl(senderImpl);
		MYBean mybean=(MYBean)WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()).getBean("mybean");
		sMSThread.setMybean(mybean);
		DataSource dataSource1=(DataSource)WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()).getBean("DataSource1");
		sMSThread.setDataSource1(dataSource1);
		DataSource dataSource2=(DataSource)WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()).getBean("DataSource2");
		sMSThread.setDataSource2(dataSource2);
		Thread t=new Thread(sMSThread); 
        t.start(); //   启动定时短信任务
	}

}
